package com.automation.ljf.strategy.context;

import com.automation.ljf.domain.dataobject.CaseStepDO;
import com.automation.ljf.strategy.OperationStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 策略context，将其注入到spring
 *
 * @author lijiefeng
 * @since 2021/8/25
 */
@Service
public class OperationStrategyContext {

    @Autowired
    private final Map<String, OperationStrategy> operationStrategyServiceMap = new ConcurrentHashMap<>();

//    public OperationStrategyContext(Map<String, OperationStrategy> strategyMap) {
//        this.operationStrategyServiceMap.clear();
//        strategyMap.forEach((k, v)-> this.operationStrategyServiceMap.put(k, v));
//    }

    public OperationStrategyContext(Map<String, OperationStrategy> strategyMap) {
        this.operationStrategyServiceMap.putAll(strategyMap);
    }

    public OperationStrategy getResource(CaseStepDO caseStepDO){
        return operationStrategyServiceMap.get(caseStepDO.getStepOperation());
    }


}
